<template>
  <div class="container">
    <div class="app-container">
      <el-button class="btn-app" type="primary" size="mini">添加权限</el-button>
      <el-table :data="list" row-key="id" :default-expand-all="true"
        ><!-- 数据带有children属性时，通过row-key属性显示 -->
        <el-table-column prop="name" label="名称"></el-table-column>
        <el-table-column prop="code" label="标识"></el-table-column>
        <el-table-column prop="description" label="描述"></el-table-column>
        <el-table-column label="操作" width="280px">
          <template v-slot="{ row }">
            <el-button
              v-if="row.type === 1"
              @click="$router.push(`/employee/detail/${row.id}`)"
              type="text"
              size="mini"
              >添加</el-button
            >
            <el-button type="text" size="mini">编辑</el-button>
            <el-popconfirm
              title="确认要删除该行数据吗"
              @onConfirm="confirmDel(row.id)"
            >
              <el-button
                slot="reference"
                size="mini"
                type="text"
                style="margin-left: 10px"
                >删除</el-button
              >
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
import { getPermissionList } from "@/api/permission";
import { transListToTreeData } from "@/utils";
export default {
  name: "Permission",
  data() {
    return {
      list: [],
    };
  },
  created() {
    this.getPermissionList();
  },
  methods: {
    async getPermissionList() {
      this.list = transListToTreeData(await getPermissionList(), 0);
    },
  },
};
</script>
<style scoped>
.btn-app {
  margin: 10px;
}
</style>
